package leetcode.LinkList;

import java.util.Stack;

public class isPalindromel {
    public static boolean process(Node head){
        Stack<Node> stack = new Stack<>();
        Node cur=head;
        while (cur!=null){
            stack.push(cur);
            cur=cur.next;
        }
        while (head!=null){
            if (head.value!=stack.pop().value){
                return false;
            }
            head=head.next;
        }
        return true;
    }
    public static boolean process2(Node head){
        if (head==null || head.next==null){
            return true;
        }
        Node right = head.next;
        Node cur = head;
        Stack<Node> stack = new Stack<>();
        //双指针找中间节点
        while (cur.next!=null && cur.next.next!=null){
            right = right.next;
            cur=cur.next.next;
        }
        while (right!=null){
            stack.push(right);
            right=right.next;
        }
        while (!stack.isEmpty()){
            if (head.value!=stack.pop().value){
                return false;
            }
            head=head.next;
        }
        return true;
    }
}
